package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.wildfirechat.pojos.PojoGroupMember;
import com.ruoyi.system.domain.GroupMember;
import com.ruoyi.system.dto.GroupMemberDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TGroup;
import com.ruoyi.system.service.ITGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * max group member countController
 * 
 * @author ruoyi
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/system/group")
public class TGroupController extends BaseController
{
    @Autowired
    private ITGroupService tGroupService;

    /**
     * 查询max group member count列表
     */
    @PreAuthorize("@ss.hasPermi('system:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(TGroup tGroup)
    {
        startPage();
        List<TGroup> list = tGroupService.selectTGroupList(tGroup);
        return getDataTable(list);
    }

    @GetMapping("/list/groupMember/{groupId}")
    public TableDataInfo listByGroupMember(@PathVariable String groupId)
    {
        startPage();
        List<GroupMemberDTO> list = tGroupService.listByGroupMember(groupId);
        return getDataTable(list);
    }

    /**
     * 导出max group member count列表
     */
    @PreAuthorize("@ss.hasPermi('system:group:export')")
    @Log(title = "max group member count", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TGroup tGroup)
    {
        List<TGroup> list = tGroupService.selectTGroupList(tGroup);
        ExcelUtil<TGroup> util = new ExcelUtil<TGroup>(TGroup.class);
        util.exportExcel(response, list, "max group member count数据");
    }

    /**
     * 获取max group member count详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tGroupService.selectTGroupById(id));
    }

    /**
     * 新增max group member count
     */
    @PreAuthorize("@ss.hasPermi('system:group:add')")
    @Log(title = "max group member count", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TGroup tGroup)
    {
        return toAjax(tGroupService.insertTGroup(tGroup));
    }

    /**
     * 修改max group member count
     */
    @PreAuthorize("@ss.hasPermi('system:group:edit')")
    @Log(title = "max group member count", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TGroup tGroup)
    {
        return toAjax(tGroupService.updateTGroup(tGroup));
    }

    @PostMapping("/groupMemberAddOrDel")
    public AjaxResult groupMemberAddOrDel(@RequestBody TGroup tGroup)
    {
        return toAjax(tGroupService.groupMemberAddOrDel(tGroup));
    }

    /**
     * 删除max group member count
     */
    @PreAuthorize("@ss.hasPermi('system:group:remove')")
    @Log(title = "max group member count", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tGroupService.deleteTGroupByIds(ids));
    }
}
